<?php
/**
 * Created by PhpStorm.
 * User: clkj1
 * Date: 2018/7/25
 * Time: 10:26
 */

session_start();
if ($_POST) {
    if (isset($_POST['type'])) {
        require_once './core/admin-sql.php';
        $sql = new AdminSql();
        switch ($_POST['type']) {
            case 'logout':
                session_unset();
                session_destroy();
                exit('{"content":0}');
                break;
            case 'addNewForm':
                $_SESSION['f-uid'] = $_POST['uid'];
                $_SESSION['f-fid'] = $_POST['fid'];
                exit('{"content":0}');
                break;
            case 'addUserSets':
                switch ($_POST['mode']) {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        $res = $sql->setUserSets($_SESSION['uid'], 2, $_POST['listJson']);
                        exit('{"state":' . $res . '}');
                        break;
                    default:
                }
                break;
            case 'adminSharePoster':
                if (isset($_POST['uid'])) {
                    $_SESSION['f-uid'] = $_POST['uid'];
                    exit('{"state":0}');
                } else {
                    exit('{"state":1}');
                }
                break;
            case 'deletePoster':
                if ($_SESSION['uid'] === $_POST['uid']) {
                    $res = $sql->deletePoster($_POST['uid'], $_POST['pid']);
                    if ($res === 0) {
                        exit('{"state":' . $res . '}');
                    } else {
                        exit('{"state":' . $res . ',"error":"非法删除"}');
                    }
                } else {
                    exit('{"state":1,"error":"非法删除"}');
                }
                break;
            case 'deletePosterSession':
                $res = $sql->deleteTempPoster($_SESSION['f-uid'], $_SESSION['f-fid']);
                if ($res === 0) {
                    unset($_SESSION['save']);
                    unset($_SESSION['f-uid']);
                    unset($_SESSION['f-fid']);
                    unset($_SESSION['image-bg-id']);
                    unset($_SESSION['image-title-id']);
                    unset($_SESSION['image-bg']);
                    unset($_SESSION['image-title']);
                    unset($_SESSION['a1']);
                    unset($_SESSION['a2']);
                    unset($_SESSION['b1']);
                    unset($_SESSION['listArray']);
                    unset($_SESSION['image-format-id']);
                    unset($_SESSION['make-done-poster']);
                    unset($_SESSION['text1']);
                    unset($_SESSION['text2']);
                    unset($_SESSION['text3']);
                    unset($_SESSION['title']);
                    unset($_SESSION['image-logo']);
                    unset($_SESSION['poster-size-kb']);
                    unset($_SESSION['code']);
                    unset($_SESSION['tp']);
                    exit(json_encode(['state'=>$res]));
                } else exit(json_encode(['state'=>$res]));
                break;
            case 'deleteApply2':
                if (isset($_POST['uid']) && isset($_POST['tid']) && isset($_POST['idJson'])) {
                    if ($_POST['uid'] === $_SESSION['uid']) {
                        $res = $sql->deleteApply2($_POST['uid'], $_POST['tid'], $_POST['idJson']);
                        exit('{"state":' . $res . ',"error":"?"}');
                    } else exit('{"state":7,"error":"?"}');
                } else exit('{"state":8,"error":"?"}');
            case 'deleteApply3':
                if (isset($_POST['uid']) && isset($_POST['tid']) && isset($_POST['pid'])) {
                    if ($_POST['uid'] === $_SESSION['uid']) {
                        $res = $sql->deleteApply3($_POST['uid'], $_POST['tid'], $_POST['pid']);
                        exit('{"state":' . $res . ',"error":"?"}');
                    } else exit('{"state":1,"error":"?"}');
                } else exit('{"state":1,"error":"?"}');
            default:
        }
    }
}